package com.futu.attraction.config;

import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FlinkConfig {

    /**
     * 创建并配置Flink流执行环境
     *
     * @return 配置好的StreamExecutionEnvironment实例
     */
    @Bean
    public StreamExecutionEnvironment streamExecutionEnvironment() {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 设置执行模式为流处理
        env.setRuntimeMode(RuntimeExecutionMode.STREAMING);

        // 设置并行度
        env.setParallelism(1);

        // 启用检查点以实现容错
        env.enableCheckpointing(60000); // 每60秒创建一次检查点

        return env;
    }
}
